package com.duke.shaking.pojo;

import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class CacheImage {
	public static final int LocationType_Net  = 0;
	public static final int LocationType_FILE = 1;
	public static final int LocationType_ASSETS = 2;
	
	protected int locationType;
	protected String url;

	public CacheImage(String url, int locationType) {
		this.url = url;
		this.locationType = locationType;
	}
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	public int getLocationType() {
		return locationType;
	}
	
	public void setLocationType(int locationType) {
		this.locationType = locationType;
	}
	
	public Bitmap loadFromAssets(Context context) {
		Bitmap image = null;
		if (url == null) {
			return null;
		}
		
	    AssetManager am = context.getResources().getAssets();
	    try  {
	        InputStream is = am.open(url);
	        image = BitmapFactory.decodeStream(is);
	        is.close();
	    }
	    catch (IOException e) {
	        e.printStackTrace();
	    }
	    return image;
	}
}
